 export default function (app) {

  app.directive('double', double);

  function double () {
    'ngInject';

    let DOUBLE_REGEXP = /^\d+(\.\d+)?$/;
    return {
      restrict: 'A',
      link: linkFn,
      require: 'ngModel'
    };

    function linkFn (scope, elem, attrs, ctrl) {
      ctrl.$validators.double = function(modelValue, viewValue) {
        if (ctrl.$isEmpty(modelValue)) {
          // consider empty models to be valid
          return true;
        }

        if (DOUBLE_REGEXP.test(viewValue)) {
          // it is valid
          return true;
        }

        // it is invalid
        return false;
     };
    }
  }
}